const { getDefaultConfig } = require("expo/metro-config");

const config = getDefaultConfig(__dirname);

// 配置调试器
config.server = {
  ...config.server,
  enhanceMiddleware: (middleware) => {
    return (req, res, next) => {
      // 允许 React Native Debugger 连接
      if (req.url === "/debugger-ui/") {
        res.setHeader("Access-Control-Allow-Origin", "*");
        res.setHeader(
          "Access-Control-Allow-Methods",
          "GET, POST, PUT, DELETE, OPTIONS"
        );
        res.setHeader(
          "Access-Control-Allow-Headers",
          "Content-Type, Authorization"
        );
      }
      return middleware(req, res, next);
    };
  },
};

module.exports = config;

